package com.yuhao.servicea.controller;

import com.google.common.base.Optional;
import com.yuhao.client.feignclient.ServiceBClient;
import com.yuhao.common.entity.serviceb.ServiceBOutput;
import com.yuhao.servicea.entity.ServiceATest;
import com.yuhao.servicea.service.ServiceATestService;
import com.yuhao.servicea.util.BaseController;
import com.yuhao.servicea.util.ResultData;
import com.yuhao.servicea.util.ResultType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/servicea")
@Api(value = "servicea test")
public class ServiceAController extends BaseController {

    @Autowired
    private ServiceATestService service;

    @Autowired
    private ServiceBClient client;


    @PostMapping("/addTest")
    @ApiOperation(value = "添加测试记录 ", notes = "传入ServiceATest")
    @ApiResponse(
            code = 200,
            message = "code == 200 成功",
            response = ResultData.class
    )
    public ResultData addTest(ServiceATest aTest) {
        service.addTest(aTest);
        return setResponseEntity(ResultType.SUCCESS.getDescription(), ResultType.SUCCESS.getCode(), "操作成功", true);
    }

    @GetMapping("/findAllTest")
    @ApiOperation(value = "查找所有test ", notes = "")
    @ApiResponse(
            code = 200,
            message = "code == 200 成功",
            response = ResultData.class
    )
    public ResultData findAllTest() {
        Optional.of(null).or("aa");
        List<ServiceATest> serviceATestList = service.findAllTest();
        return setResponseEntity(ResultType.SUCCESS.getDescription(), ResultType.SUCCESS.getCode(), serviceATestList, true);
    }

    @GetMapping("/findAllSBTest")
    @ApiOperation(value = "查找所有SBtest ", notes = "")
    @ApiResponse(
            code = 200,
            message = "code == 200 成功",
            response = ResultData.class
    )
    public ResultData findAllSBTest() {
        List<ServiceBOutput> serviceBOPList = client.getServicebList();
        return setResponseEntity(ResultType.SUCCESS.getDescription(), ResultType.SUCCESS.getCode(), serviceBOPList, true);
    }
}
